Skip to content

Conversation

@helenKaryamsetty
Copy link
Member

@helenKaryamsetty helenKaryamsetty commented Sep 26, 2024

πŸ“‹ Description

JIRA ID: AMM-871

Changes to fetch mapped ABDM Facility Id from job location.


βœ… Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • πŸ”₯ Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • πŸ›  Refactor (change that is neither a fix nor a new feature)
  • βš™οΈ Config change (configuration file or build script updates)
  • πŸ“š Documentation (updates to docs or readme)
  • πŸ§ͺ Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • πŸš€ Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

ℹ️ Additional Information

Please describe how the changes were tested, and include any relevant screenshots, logs, or other information that provides additional context.

Summary by CodeRabbit

  • New Features

    • Introduced a REST controller for managing ABDM facility requests, enabling retrieval of facility details based on work location.
    • Added new fields to enhance the data model for storing ABDM facility identifiers.
    • Implemented a repository interface for custom queries related to ABDM facilities.
    • Created a service interface and its implementation for accessing mapped ABDM facilities.
  • Bug Fixes

    • Improved error handling in the facility retrieval process.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 26, 2024

Walkthrough

The changes introduce a new REST controller, AbdmFacilityController, for handling requests related to ABDM facilities, including a method for retrieving facility details based on a work location ID. Additionally, two fields are added to the ProviderServiceAddressMapping class, and a new repository interface, AbdmFacilityRepository, is created to support data access. The service layer is enhanced with the AbdmFacilityService interface and its implementation, AbdmFacilityServiceImpl, to facilitate the business logic associated with ABDM facilities.

Changes

File Path Change Summary
src/main/java/com/iemr/common/controller/abdmfacility/AbdmFacilityController.java Class added: AbdmFacilityController. Method added: getAbdmFacilityDetails(...).
src/main/java/com/iemr/common/data/users/ProviderServiceAddressMapping.java Fields added: private String abdmFacilityID, private String abdmFacilityName.
src/main/java/com/iemr/common/repository/abdmfacility/AbdmFacilityRepository.java Interface added: AbdmFacilityRepository. Method added: getAbdmFacility(@Param("pssmID") int pssmID).
src/main/java/com/iemr/common/service/abdmfacility/AbdmFacilityService.java Interface added: AbdmFacilityService. Method added: getMappedAbdmFacility(int psmId).
src/main/java/com/iemr/common/service/abdmfacility/AbdmFacilityServiceImpl.java Class added: AbdmFacilityServiceImpl. Method added: getMappedAbdmFacility(int psmId).

Poem

In the fields of code we play,
New paths and services come our way.
With controllers and fields so bright,
ABDM facilities take flight!
A hop, a skip, a joyful cheer,
For every change that brings us near! πŸ‡βœ¨


πŸ“œ Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 60937ed and c5c73cf.

πŸ“’ Files selected for processing (1)
  • src/main/java/com/iemr/common/service/abdmfacility/AbdmFacilityServiceImpl.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/com/iemr/common/service/abdmfacility/AbdmFacilityServiceImpl.java

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❀️ Share
πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarCloud

@helenKaryamsetty helenKaryamsetty marked this pull request as ready for review October 8, 2024 07:52
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (7)
src/main/java/com/iemr/common/service/abdmfacility/AbdmFacilityService.java (2)

5-5: Consider adding JavaDoc and reviewing the return type.

The method signature is clear, but it could benefit from the following improvements:

  1. Add a JavaDoc comment to explain the method's purpose, parameter, and return value.
  2. Consider using a more specific return type if possible, such as an object representing the ABDM facility, instead of a String.

Example JavaDoc:

/**
 * Retrieves the mapped ABDM facility for a given provider service mapping ID.
 *
 * @param psmId The Provider Service Mapping ID
 * @return The mapped ABDM facility identifier or details
 */
public String getMappedAbdmFacility(int psmId);

1-7: LGTM: Well-structured service interface.

The AbdmFacilityService interface is well-defined and follows good practices for service layer design. It provides a clear contract for implementing classes to handle ABDM facility mapping functionality.

Minor suggestion: Consider adding an import statement for java.lang.String at the beginning of the file for explicitness, although it's not strictly necessary as String is automatically imported in Java.

import java.lang.String;
src/main/java/com/iemr/common/service/abdmfacility/AbdmFacilityServiceImpl.java (1)

1-22: Overall assessment: Good implementation with room for improvement.

The AbdmFacilityServiceImpl class provides the necessary functionality for retrieving mapped ABDM facility information. However, there are a few areas where the implementation can be enhanced:

  1. Consider using constructor injection instead of field injection for better testability and immutability.
  2. Refine the getMappedAbdmFacility method to handle potential null values and return more meaningful data.
  3. Verify and correct the potential typo in the repository method name (getAbdamFacility vs getAbdmFacility).
  4. Add appropriate exception handling and logging throughout the service.

These improvements will make the service more robust, easier to test, and more maintainable in the long run.

src/main/java/com/iemr/common/repository/abdmfacility/AbdmFacilityRepository.java (1)

1-17: Consider adding documentation comments.

To improve code readability and maintainability, consider adding Javadoc comments to the interface and the custom query method. This will help other developers understand the purpose and usage of this repository.

Here's an example of how you could add documentation:

/**
 * Repository interface for managing ABDM (Ayushman Bharat Digital Mission) facility data.
 * This interface provides CRUD operations for ProviderServiceAddressMapping entities
 * and includes a custom query for retrieving facility details.
 */
@Repository
public interface AbdmFacilityRepository extends CrudRepository<ProviderServiceAddressMapping, Integer> {

    /**
     * Retrieves the ABDM facility details for a given Provider Service Address Mapping ID.
     *
     * @param pssmID The Provider Service Address Mapping ID
     * @return The ProviderServiceAddressMapping entity corresponding to the given ID
     */
    @Query("SELECT v from ProviderServiceAddressMapping v where v.pSAddMapID = :pssmID")
    ProviderServiceAddressMapping getAbdmFacility(@Param("pssmID") int pssmID);
}
src/main/java/com/iemr/common/controller/abdmfacility/AbdmFacilityController.java (2)

16-17: Remove unused import.

The @RequestBody annotation is imported but not used in the controller. Consider removing this unused import to keep the code clean.

Apply this change:

-import io.swagger.v3.oas.annotations.parameters.RequestBody;

46-47: Improve logging for better traceability.

The current log message doesn't include the workLocationId, which could be useful for debugging. Consider adding more context to the log message.

Enhance the log message as follows:

-		logger.info("Get ABDM Registered facilities API response" + response.toString());
+		logger.info("Get ABDM Registered facilities API response for workLocationId {}: {}", workLocationId, response);
src/main/java/com/iemr/common/data/users/ProviderServiceAddressMapping.java (1)

84-91: LGTM! Consider adding JavaDoc comments for the new fields.

The addition of abdmFacilityID and abdmFacilityName fields is well-implemented and aligns with the PR objective. The use of @Expose and @Column annotations is correct and consistent with the existing code style.

To improve code documentation, consider adding JavaDoc comments for these new fields. For example:

/**
 * The unique identifier for the ABDM facility.
 */
@Expose
@Column(name = "AbdmFacilityID")
private String abdmFacilityID;

/**
 * The name of the ABDM facility.
 */
@Expose
@Column(name = "AbdmFacilityName")
private String abdmFacilityName;
πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

πŸ“₯ Commits

Files that changed from the base of the PR and between 0c9f8b3 and 262d000.

πŸ“’ Files selected for processing (5)
  • src/main/java/com/iemr/common/controller/abdmfacility/AbdmFacilityController.java (1 hunks)
  • src/main/java/com/iemr/common/data/users/ProviderServiceAddressMapping.java (2 hunks)
  • src/main/java/com/iemr/common/repository/abdmfacility/AbdmFacilityRepository.java (1 hunks)
  • src/main/java/com/iemr/common/service/abdmfacility/AbdmFacilityService.java (1 hunks)
  • src/main/java/com/iemr/common/service/abdmfacility/AbdmFacilityServiceImpl.java (1 hunks)
🧰 Additional context used
πŸ”‡ Additional comments (9)
src/main/java/com/iemr/common/service/abdmfacility/AbdmFacilityService.java (2)

1-1: LGTM: Package declaration is appropriate.

The package name com.iemr.common.service.abdmfacility follows Java naming conventions and correctly indicates its purpose within the service layer for ABDM facility-related functionality.


3-3: LGTM: Interface declaration is well-defined.

The AbdmFacilityService interface is appropriately named and declared. It follows Java naming conventions and clearly indicates its purpose in the system.

src/main/java/com/iemr/common/service/abdmfacility/AbdmFacilityServiceImpl.java (3)

1-8: LGTM: Package declaration and imports are correct.

The package name is appropriate for the service implementation, and all necessary imports are present without any unused imports.


9-10: LGTM: Class declaration and annotation are correct.

The class is properly annotated with @service, follows naming conventions, and implements the AbdmFacilityService interface.


15-20: ⚠️ Potential issue

Refine the implementation of getMappedAbdmFacility method.

There are a few points to consider in this method:

  1. There's a typo in the repository method name: getAbdamFacility should likely be getAbdmFacility.
  2. Returning toString() directly might not provide the most useful or formatted output for a service method.
  3. There's no null check before calling toString(), which could lead to a NullPointerException.

Here's a suggested improvement:

 @Override
 public String getMappedAbdmFacility(int psmId) {
-    ProviderServiceAddressMapping res = abdmFacilityRepo.getAbdamFacility(psmId);
-    return res.toString();
+    ProviderServiceAddressMapping res = abdmFacilityRepo.getAbdmFacility(psmId);
+    if (res == null) {
+        return null; // or throw a custom exception
+    }
+    // Return a specific field or a formatted string instead of toString()
+    return res.getAbdmFacilityId(); // Assuming this method exists
 }

Also, consider adding appropriate exception handling and logging.

To verify the correct repository method name, please run:

src/main/java/com/iemr/common/repository/abdmfacility/AbdmFacilityRepository.java (2)

1-9: LGTM: Package declaration and imports are appropriate.

The package name and imports are well-structured and contain all necessary components for the repository interface.


10-11: LGTM: Interface declaration is well-defined.

The AbdmFacilityRepository interface is correctly declared, extending CrudRepository for ProviderServiceAddressMapping entities and properly annotated with @Repository.

src/main/java/com/iemr/common/controller/abdmfacility/AbdmFacilityController.java (2)

19-26: Class structure and annotations look good.

The controller is properly set up with the correct annotations, logger initialization, and dependency injection for the AbdmFacilityService.


31-31: Consider using the Authorization header.

The Authorization header is received as a parameter but not used in the method. If it's not needed, consider removing it. If it should be used for authentication, make sure to implement the necessary checks.

To verify if the Authorization header is used elsewhere in the service layer, run the following script:

βœ… Verification successful

Remove Unused Authorization Parameter

The Authorization header is received as a parameter in the getStoreStockDetails method but is not utilized. If authentication is required, please implement the necessary checks; otherwise, consider removing the unused parameter.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of Authorization header in the service layer
rg --type java -g 'src/main/java/com/iemr/common/service/**/*.java' 'Authorization'

Length of output: 9603

@drtechie
Copy link
Member

drtechie commented Nov 4, 2024

@helenKaryamsetty several comments from coderabbit including typos and function names are not addressed. Have you checked these comments?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (2)
src/main/java/com/iemr/common/controller/abdmfacility/AbdmFacilityController.java (2)

17-17: Remove unused import.

The @RequestBody annotation import is not used in this GET endpoint and should be removed.

-import io.swagger.v3.oas.annotations.parameters.RequestBody;

29-29: Enhance API documentation.

The OpenAPI documentation could be more detailed. Consider adding:

  • A more descriptive summary
  • Response descriptions
  • Parameter descriptions
-@Operation(summary = "Get Abdm facility mapped to worklocation")
+@Operation(
+    summary = "Retrieve ABDM facility details for a work location",
+    description = "Fetches the mapped ABDM Facility ID and name for the given work location ID",
+    parameters = {
+        @Parameter(name = "workLocationId", description = "The ID of the work location to fetch ABDM facility details for"),
+        @Parameter(name = "Authorization", description = "Bearer token for authentication", in = ParameterIn.HEADER)
+    }
+)
πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 262d000 and e975305.

πŸ“’ Files selected for processing (1)
  • src/main/java/com/iemr/common/controller/abdmfacility/AbdmFacilityController.java (1 hunks)
🧰 Additional context used
πŸ““ Learnings (1)
src/main/java/com/iemr/common/controller/abdmfacility/AbdmFacilityController.java (1)
Learnt from: helenKaryamsetty
PR: PSMRI/Common-API#123
File: src/main/java/com/iemr/common/controller/abdmfacility/AbdmFacilityController.java:41-45
Timestamp: 2024-11-20T07:23:22.514Z
Learning: In the `Common-API` codebase, exception handling within controller classes like `AbdmFacilityController.java` is managed using the `OutputResponse` class, and it is not required to catch specific exceptions separately. General exception handling is sufficient in this context.
πŸ”‡ Additional comments (1)
src/main/java/com/iemr/common/controller/abdmfacility/AbdmFacilityController.java (1)

19-26: LGTM!

The class setup follows Spring Boot best practices with proper annotations, logging, and dependency injection.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@helenKaryamsetty
Copy link
Member Author

@helenKaryamsetty several comments from coderabbit including typos and function names are not addressed. Have you checked these comments?

yes committed those changes

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 7, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarQube Cloud

Copy link
Contributor

@ravishanigarapu ravishanigarapu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks fine

@ravishanigarapu ravishanigarapu merged commit 76db865 into develop Dec 9, 2024
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants